package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GridLogs;
import com.ruoyi.system.service.IGridLogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日志管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/system/logs")
public class GridLogsController extends BaseController
{
    @Autowired
    private IGridLogsService gridLogsService;

    /**
     * 查询日志管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:logs:list')")
    @GetMapping("/list")
    public TableDataInfo list(GridLogs gridLogs)
    {
        startPage();
        List<GridLogs> list = gridLogsService.selectGridLogsList(gridLogs);
        return getDataTable(list);
    }

    /**
     * 导出日志管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:logs:export')")
    @Log(title = "日志管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GridLogs gridLogs)
    {
        List<GridLogs> list = gridLogsService.selectGridLogsList(gridLogs);
        ExcelUtil<GridLogs> util = new ExcelUtil<GridLogs>(GridLogs.class);
        util.exportExcel(response, list, "日志管理数据");
    }

    /**
     * 获取日志管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:logs:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Integer logId)
    {
        return AjaxResult.success(gridLogsService.selectGridLogsByLogId(logId));
    }

    /**
     * 新增日志管理
     */
    @PreAuthorize("@ss.hasPermi('system:logs:add')")
    @Log(title = "日志管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GridLogs gridLogs)
    {
        return toAjax(gridLogsService.insertGridLogs(gridLogs));
    }

    /**
     * 修改日志管理
     */
    @PreAuthorize("@ss.hasPermi('system:logs:edit')")
    @Log(title = "日志管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GridLogs gridLogs)
    {
        return toAjax(gridLogsService.updateGridLogs(gridLogs));
    }

    /**
     * 删除日志管理
     */
    @PreAuthorize("@ss.hasPermi('system:logs:remove')")
    @Log(title = "日志管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Integer[] logIds)
    {
        return toAjax(gridLogsService.deleteGridLogsByLogIds(logIds));
    }
}
